package com.hns.can.report.web;

import com.hns.can.common.domain.GridPage;
import com.hns.can.common.web.BaseController;
import com.hns.can.report.entity.CommCarArrivalLeavesInfoEntity;
import com.hns.can.safety.vo.OverspeedStatisticsParamVo;
import com.hns.can.safety.vo.SpedReportSummaryVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.tool.export.ExportUtil;
import com.hns.tool.pub.DateTool;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hns.can.report.service.NoReasonToStopService;

import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.report.vo.NoReasonToStopVo;
import com.hns.can.base.entity.SysUserEntity;

import org.springframework.web.servlet.tags.Param;

import javax.servlet.http.HttpServletResponse;

import java.net.URLEncoder;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Lan on 2016/8/10.
 */

@Controller
@RequestMapping("noReasonToStop")
public class NoReasonToStopController  extends BaseController {

    @Autowired
    private NoReasonToStopService noReasonToStopService;
    final private String[] headerNames = {"车牌号", "车辆编号" ,"运营线路", "所属机构","方向","离站站点", "离站时间", "进站站点", "进站时", "间隔时长" };
    final private String[] headerFields = {"licPltNo", "carInCd" ,"lineName", "organName", "upDn","leaveStnName","leaveTime", "arriveStnName", "arriveTime","intervalMinute"};


    /**
     * @param entity
     * @param request
     * @param response
     * @throws Exception
     * @author:lan
     * @创建日期:2016-08-10
     * @功能说明：查询，返回page对象
     */
    @RequestMapping("/searchNoReasonToStopPage")
    @ResponseBody
    public Object searchNoReasonToStopPage(NoReasonToStopVo vo) throws Exception {
        SysUserEntity user = this.getCurrentUser().getUser();
        vo.setCorpId(user.getCorpId());
        if(!"".equals(vo.getStopTime())){
            vo.setStopTime(String.valueOf(Integer.parseInt(vo.getStopTime())*60));
        }
        Pagination page = noReasonToStopService.searchNoReasonToStopPage(vo);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }

    /**
     * 导出excel
     * @param vo
     * @param request
     * @param response
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/exportNoReasonToStopExcel")
    public void exportNoReasonToStopExcel(NoReasonToStopVo vo, HttpServletResponse response) throws Exception {
        SysUserEntity user = this.getCurrentUser().getUser();
        vo.setCorpId(user.getCorpId());
        List<CommCarArrivalLeavesInfoEntity> list = noReasonToStopService.searchNoReasonToStopList(vo);
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "excel", URLEncoder.encode("无故停趟", "UTF-8") + DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "无故停靠");
    }

    /**
     * 导出超速统计pdf
     * @param conditionVo
     * @param request
     * @param response
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/exportNoReasonToStopPdf")
    public void exportNoReasonToStopPdf(NoReasonToStopVo vo,HttpServletResponse response) throws Exception {
        SysUserEntity user = this.getCurrentUser().getUser();
        vo.setCorpId(user.getCorpId());
        List<CommCarArrivalLeavesInfoEntity> list = noReasonToStopService.searchNoReasonToStopList(vo);
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "pdf", URLEncoder.encode("无故停趟", "UTF-8") + DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "无故停靠");
    }

}
